import json
import os

from cn.boz.utils.ProjectUtils import ProjectUtils
from cn.boz.utils.datatheif.dataTheif import DataTheif


def test03():
    dt = DataTheif()
    dt.theifForProductList(1, 48, True)


def test04():
    """
    转化商品到实际可以使用的商品
    """
    path="/Volumes/Mac/Code/pycharm/MyAI/temp/merchant/product/"
    fpath = os.path.join(ProjectUtils.getProjectPath(), path)
    fs = os.listdir(fpath)
    # fs = list(filter(lambda f: 'json' in f, fs))
    destPath = '%s/convert' % (fpath)
    if not os.path.isdir(destPath):
        os.makedirs(destPath)
    for f in fs:
        with open(os.path.join(fpath, f), 'r+') as fp:
            with open(os.path.join(destPath, '%s.json' % (f)), 'w+') as fop:
                obj = json.load(fp)
                data = obj['data']
                data['_id'] = data['id']
                del data['id']
                data['price'] = 0
                json.dump(data, ensure_ascii=False, fp=fop)
    for f in os.listdir(destPath):
        with open(os.path.join(destPath, f), 'r+') as fp:
            text = fp.read()
            fp.seek(0)
            fp.truncate()
            text = text.replace('https://aidi-public.oss-cn-zhangjiakou.aliyuncs.com', '', -1)
            fp.write(text)
            print(text)

def combine():
    path="/Volumes/Mac/Code/pycharm/MyAI/temp/merchant/product/convert/"
    fpath = os.path.join(ProjectUtils.getProjectPath(), path)
    fs = os.listdir(fpath)
    list=[]
    for f in fs:
        with open(os.path.join(path,f)) as fp:
            loadd=json.load(fp)
            list.append(loadd)
    print(list)

def test05():
    """
    偷取商品，按照给定的ID进行偷取
    """
    dt = DataTheif()
    items = ['10397','10396','10395','10394','10393','10392','10391','10390']
    for item in items:
        dt.theifForProductById(item)

combine()